<template>
  <div class="comparison-container">
    <h2>精液动态分析报告 - 三期数据对比分析</h2>
    <p class="comparison-date">对比时间：2025年5月25日 vs 2025年6月29日 vs 2025年7月29日</p>
    
    <!-- 基本信息对比 -->
    <div class="basic-info-comparison">
      <h3>三期检测数据对比</h3>
      <div class="comparison-table">
        <table>
          <thead>
            <tr>
              <th>检测项目</th>
              <th>5月25日</th>
              <th>6月29日</th>
              <th>7月29日</th>
              <th>变化趋势</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>精液量(ml)</td>
              <td>3.50</td>
              <td>4.80</td>
              <td>2.00</td>
              <td class="fluctuation">波动较大</td>
            </tr>
            <tr>
              <td>精子密度(×10⁶/ml)</td>
              <td>15.81</td>
              <td>17.44</td>
              <td>18.52</td>
              <td class="increase">持续改善</td>
            </tr>
            <tr>
              <td>精子活动率(%)</td>
              <td>38.67</td>
              <td>18.24</td>
              <td>44.59</td>
              <td class="fluctuation">波动明显</td>
            </tr>
            <tr>
              <td>A级精子(%)</td>
              <td>13.33</td>
              <td>4.05</td>
              <td>8.78</td>
              <td class="decrease">整体下降</td>
            </tr>
            <tr>
              <td>B级精子(%)</td>
              <td>21.33</td>
              <td>11.49</td>
              <td>27.70</td>
              <td class="fluctuation">波动较大</td>
            </tr>
            <tr>
              <td>A+B级精子(%)</td>
              <td>34.67</td>
              <td>15.54</td>
              <td>36.49</td>
              <td class="fluctuation">波动明显</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

    <!-- 图表对比区域 -->
    <div class="charts-comparison">
      <!-- 精子密度趋势图 -->
      <div class="chart-card">
        <h3>精子密度变化趋势</h3>
        <v-chart class="chart" :option="densityTrendOption" />
      </div>

      <!-- 精子活动率趋势图 -->
      <div class="chart-card">
        <h3>精子活动率变化趋势</h3>
        <v-chart class="chart" :option="motilityTrendOption" />
      </div>

      <!-- 精子分类分布对比 -->
      <div class="chart-card">
        <h3>三期精子分类分布对比</h3>
        <v-chart class="chart" :option="spermDistributionOption" />
      </div>

      <!-- 关键参数雷达图 -->
      <div class="chart-card">
        <h3>关键参数三期对比</h3>
        <v-chart class="chart" :option="radarComparisonOption" />
      </div>
    </div>

    <!-- 详细分析 -->
    <div class="detailed-analysis">
      <h3>三期检测详细分析</h3>
      <div class="analysis-grid">
        <div class="analysis-item">
          <h4>📊 5月25日检测</h4>
          <div class="analysis-content">
            <p><strong>优势：</strong>精液量充足(3.50ml)，A级精子比例相对较高(13.33%)</p>
            <p><strong>问题：</strong>精子密度偏低(15.81×10⁶/ml)，活动率不足(38.67%)</p>
            <p><strong>状态：</strong>基础指标尚可，但关键指标不达标</p>
          </div>
        </div>
        
        <div class="analysis-item">
          <h4>📊 6月29日检测</h4>
          <div class="analysis-content">
            <p><strong>优势：</strong>精液量最佳(4.80ml)，精子密度有所提升(17.44×10⁶/ml)</p>
            <p><strong>问题：</strong>活动率严重下降(18.24%)，A级精子比例最低(4.05%)</p>
            <p><strong>状态：</strong>数量指标改善，但质量指标明显恶化</p>
          </div>
        </div>
        
        <div class="analysis-item">
          <h4>📊 7月29日检测</h4>
          <div class="analysis-content">
            <p><strong>优势：</strong>精子密度最高(18.52×10⁶/ml)，活动率最佳(44.59%)</p>
            <p><strong>问题：</strong>精液量减少(2.00ml)，A级精子比例仍偏低(8.78%)</p>
            <p><strong>状态：</strong>质量指标明显改善，但数量指标下降</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 改善情况总结 -->
    <div class="improvement-summary">
      <h3>三期检测改善情况总结</h3>
      <div class="summary-grid">
        <div class="summary-item positive">
          <div class="icon">📈</div>
          <div class="content">
            <h4>持续改善项目</h4>
            <ul>
              <li>精子密度：15.81 → 17.44 → 18.52 (持续上升)</li>
              <li>整体趋势向好，接近正常标准(≥20×10⁶/ml)</li>
            </ul>
          </div>
        </div>
        
        <div class="summary-item warning">
          <div class="icon">⚠️</div>
          <div class="content">
            <h4>波动较大项目</h4>
            <ul>
              <li>精子活动率：38.67% → 18.24% → 44.59%</li>
              <li>精液量：3.50ml → 4.80ml → 2.00ml</li>
              <li>A级精子：13.33% → 4.05% → 8.78%</li>
            </ul>
          </div>
        </div>
        
        <div class="summary-item negative">
          <div class="icon">📉</div>
          <div class="content">
            <h4>仍需关注项目</h4>
            <ul>
              <li>所有检测中精子密度均未达到正常标准</li>
              <li>精子活动率始终低于60%的正常标准</li>
              <li>A级精子比例持续偏低</li>
            </ul>
          </div>
        </div>
      </div>
    </div>

    <!-- 医学建议 -->
    <div class="medical-recommendations">
      <h3>医学建议</h3>
      <div class="recommendations-content">
        <div class="recommendation-item">
          <h4>✅ 积极方面</h4>
          <p>精子密度呈现持续改善趋势，说明治疗措施有效，建议继续当前治疗方案。</p>
        </div>
        <div class="recommendation-item">
          <h4>⚠️ 需要关注</h4>
          <p>6月29日检测显示活动率明显下降，可能存在临时性因素影响，建议分析原因。</p>
        </div>
        <div class="recommendation-item">
          <h4>📋 后续建议</h4>
          <p>建议继续治疗，重点关注精子活动率和A级精子比例的稳定性，3个月后复查。</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { BarChart, LineChart, PieChart, RadarChart } from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  GridComponent
} from 'echarts/components'
import VChart from 'vue-echarts'

use([
  CanvasRenderer,
  BarChart,
  LineChart,
  PieChart,
  RadarChart,
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  GridComponent
])

// 精子密度趋势图
const densityTrendOption = ref({
  title: {
    text: '精子密度变化趋势',
    left: 'center'
  },
  tooltip: {
    trigger: 'axis'
  },
  legend: {
    data: ['实际值', '正常标准'],
    top: '10%'
  },
  xAxis: {
    type: 'category',
    data: ['5月25日', '6月29日', '7月29日']
  },
  yAxis: {
    type: 'value',
    name: '×10⁶/ml'
  },
  series: [
    {
      name: '实际值',
      type: 'line',
      data: [15.81, 17.44, 18.52],
      itemStyle: { color: '#5470c6' },
      lineStyle: { width: 3 },
      symbol: 'circle',
      symbolSize: 8
    },
    {
      name: '正常标准',
      type: 'line',
      data: [20, 20, 20],
      itemStyle: { color: '#91cc75' },
      lineStyle: { type: 'dashed', width: 2 }
    }
  ]
})

// 精子活动率趋势图
const motilityTrendOption = ref({
  title: {
    text: '精子活动率变化趋势',
    left: 'center'
  },
  tooltip: {
    trigger: 'axis'
  },
  legend: {
    data: ['活动率', '正常标准'],
    top: '10%'
  },
  xAxis: {
    type: 'category',
    data: ['5月25日', '6月29日', '7月29日']
  },
  yAxis: {
    type: 'value',
    name: '%'
  },
  series: [
    {
      name: '活动率',
      type: 'line',
      data: [38.67, 18.24, 44.59],
      itemStyle: { color: '#ee6666' },
      lineStyle: { width: 3 },
      symbol: 'circle',
      symbolSize: 8
    },
    {
      name: '正常标准',
      type: 'line',
      data: [60, 60, 60],
      itemStyle: { color: '#91cc75' },
      lineStyle: { type: 'dashed', width: 2 }
    }
  ]
})

// 精子分类分布对比
const spermDistributionOption = ref({
  title: {
    text: '三期精子分类分布对比',
    left: 'center'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  legend: {
    data: ['A级精子', 'B级精子', 'C级精子', 'D级精子'],
    top: '10%'
  },
  xAxis: {
    type: 'category',
    data: ['5月25日', '6月29日', '7月29日']
  },
  yAxis: {
    type: 'value',
    name: '%'
  },
  series: [
    {
      name: 'A级精子',
      type: 'bar',
      stack: 'total',
      data: [13.33, 4.05, 8.78],
      itemStyle: { color: '#91cc75' }
    },
    {
      name: 'B级精子',
      type: 'bar',
      stack: 'total',
      data: [21.33, 11.49, 27.70],
      itemStyle: { color: '#5470c6' }
    },
    {
      name: 'C级精子',
      type: 'bar',
      stack: 'total',
      data: [4.00, 2.70, 8.11],
      itemStyle: { color: '#fac858' }
    },
    {
      name: 'D级精子',
      type: 'bar',
      stack: 'total',
      data: [61.33, 81.76, 55.41],
      itemStyle: { color: '#ee6666' }
    }
  ]
})

// 关键参数雷达图对比
const radarComparisonOption = ref({
  title: {
    text: '关键参数三期对比',
    left: 'center'
  },
  tooltip: {
    trigger: 'item'
  },
  legend: {
    data: ['5月25日', '6月29日', '7月29日'],
    bottom: '5%'
  },
  radar: {
    indicator: [
      { name: '精子密度', max: 25 },
      { name: '精子活动率', max: 50 },
      { name: 'A级精子', max: 20 },
      { name: 'B级精子', max: 30 },
      { name: '精液量', max: 6 }
    ]
  },
  series: [
    {
      name: '关键参数',
      type: 'radar',
      data: [
        {
          value: [15.81, 38.67, 13.33, 21.33, 3.50],
          name: '5月25日',
          itemStyle: { color: '#5470c6' },
          areaStyle: { color: 'rgba(84, 112, 198, 0.3)' }
        },
        {
          value: [17.44, 18.24, 4.05, 11.49, 4.80],
          name: '6月29日',
          itemStyle: { color: '#fac858' },
          areaStyle: { color: 'rgba(250, 200, 88, 0.3)' }
        },
        {
          value: [18.52, 44.59, 8.78, 27.70, 2.00],
          name: '7月29日',
          itemStyle: { color: '#91cc75' },
          areaStyle: { color: 'rgba(145, 204, 117, 0.3)' }
        }
      ]
    }
  ]
})
</script>

<style scoped>
.comparison-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.comparison-container h2 {
  text-align: center;
  color: #333;
  margin-bottom: 10px;
  font-size: 2rem;
}

.comparison-date {
  text-align: center;
  color: #666;
  margin-bottom: 30px;
  font-size: 1.1rem;
}

.basic-info-comparison {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 30px;
}

.basic-info-comparison h3 {
  margin: 0 0 20px 0;
  color: #333;
  text-align: center;
}

.comparison-table {
  overflow-x: auto;
}

.comparison-table table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.comparison-table th,
.comparison-table td {
  padding: 12px;
  text-align: center;
  border-bottom: 1px solid #eee;
}

.comparison-table th {
  background: #5470c6;
  color: white;
  font-weight: bold;
}

.increase {
  color: #28a745;
  font-weight: bold;
}

.decrease {
  color: #dc3545;
  font-weight: bold;
}

.fluctuation {
  color: #ffc107;
  font-weight: bold;
}

.charts-comparison {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(600px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.chart-card {
  background: white;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.chart-card h3 {
  margin: 0 0 15px 0;
  text-align: center;
  color: #333;
}

.chart {
  height: 350px;
  width: 100%;
}

.detailed-analysis {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 30px;
}

.detailed-analysis h3 {
  margin: 0 0 20px 0;
  color: #333;
  text-align: center;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
}

.analysis-item {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.analysis-item h4 {
  margin: 0 0 15px 0;
  color: #333;
  font-size: 1.1rem;
}

.analysis-content p {
  margin: 0 0 10px 0;
  color: #666;
  line-height: 1.5;
}

.improvement-summary {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 30px;
}

.improvement-summary h3 {
  margin: 0 0 20px 0;
  color: #333;
  text-align: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
}

.summary-item {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: flex-start;
  gap: 15px;
}

.summary-item.positive {
  border-left: 4px solid #28a745;
}

.summary-item.warning {
  border-left: 4px solid #ffc107;
}

.summary-item.negative {
  border-left: 4px solid #dc3545;
}

.summary-item .icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.summary-item .content h4 {
  margin: 0 0 10px 0;
  color: #333;
}

.summary-item .content ul {
  margin: 0;
  padding-left: 20px;
}

.summary-item .content li {
  margin-bottom: 5px;
  color: #666;
}

.medical-recommendations {
  background: #e3f2fd;
  padding: 20px;
  border-radius: 8px;
}

.medical-recommendations h3 {
  margin: 0 0 20px 0;
  color: #333;
  text-align: center;
}

.recommendations-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.recommendation-item {
  background: white;
  padding: 15px;
  border-radius: 6px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.recommendation-item h4 {
  margin: 0 0 10px 0;
  color: #333;
}

.recommendation-item p {
  margin: 0;
  color: #666;
  line-height: 1.5;
}

@media (max-width: 768px) {
  .charts-comparison {
    grid-template-columns: 1fr;
  }
  
  .analysis-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }
  
  .recommendations-content {
    grid-template-columns: 1fr;
  }
}
</style> 